import numpy as np


def cot(x):
	return np.cos(x) / np.sin(x)


def getQuadrant(vec):
	if len(vec) == 2:
		x = vec[0]
		y = vec[1]
		if x > 0 and y > 0:
			return 1
		if x < 0 and y > 0:
			return 2
		if x < 0 and y < 0:
			return 3
		if x > 0 and y < 0:
			return 4
		if x > 0 and y == 0:
			return 4.5
		if x < 0 and y == 0:
			return 2.5
		if x == 0 and y > 0:
			return 1.5
		if x == 0 and y < 0:
			return 3.5
		if x == 0 and y == 0:
			return 0


def azimuth(pointA, pointB):
	dx = 0
	dy = 0
	try:
		dx = pointB.x - pointA.x
		dy = pointB.y - pointA.y
	except AttributeError as e:
		if str(e) == "'numpy.ndarray' object has no attribute 'x'":
			dx, dy = pointB - pointA
	o = abs(np.rad2deg(np.arctan(dy / dx)))
	qua = getQuadrant([dx, dy])
	if 1 <= qua <= 1.5 or qua == 4.5:
		return o
	if 2 <= qua <= 2.5:
		return 180 - o
	if 3 <= qua <= 3.5:
		return 180 + o
	if 4 <= qua:
		return 360 - o


def dec2dms(deci):
	d = int(deci)
	dr = deci - d
	m = int(dr * 60)
	mr = dr * 60 - m
	s = mr * 60
	return d, m, s


def dms2dec(dms):
	d, m, s = dms
	return d + m / 60 + s / 3600